package com.nave.segundaguerra.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.HorizontalScrollView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.ZoomControls;

import com.example.honraepodercliente.R;
import com.nave.segundaguerra.activity.views.GameView;
import com.nave.segundaguerra.servidorecliente.util.ActivityUtil;
import com.nave.segundaguerra.servidorecliente.util.ViewUtil;

public class GameplayActivity extends Activity {

	private final String TAG = "GameActivity";
	
	private ScrollView scrollView;
	private HorizontalScrollView hScrollView;
	private GameView gameView;

	private RelativeLayout container;
	private int currentX;
	private int currentY;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ViewUtil.enableMainConfig(this);

		setContentView(R.layout.activity_gameplay);

		ActivityUtil.setCurrentActivity(this);
		
		container = (RelativeLayout) findViewById(R.id.container);
		this.gameView = new GameView(getApplicationContext(),
				ConnectionSet.getConnection(), container);
		
		container.setOnTouchListener(new OnTouchListener() {
			
			public boolean onTouch(View view, MotionEvent event) {
				gameView.onTouchEvent(event);
				return true;
			}
		});

		int top = 0;
		int left = 0;

		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		layoutParams.setMargins(left, top, 0, 0);
		
		container.addView(gameView, layoutParams);
		
		// //setContentView(this.gameView);
		//
		// this.scrollView = (ScrollView)
		// findViewById(R.id.gamePlay_scrollView);
		// this.hScrollView = (HorizontalScrollView)
		// findViewById(R.id.gamePlay_hScrollView);
		//
		// this.hScrollView.setOnTouchListener(new OnTouchListener() {
		//
		// public boolean onTouch(View v, MotionEvent event) {
		// gameView.onTouchEvent(event);
		// return false;
		// }
		// });
		//
		// this.hScrollView.addView(gameView);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.gameplay, menu);
		return true;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		this.gameView.killMeSoftly();
	}

}
